#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time     : 2020/10/16 17:18
# @Author   : BYF
# file      : test.py
# @version  :

from lefull.models import MarketingCouponTemplate, MarketingCouponRule
from lefull.common.db import DataBase

"""
db = DataBase()
session = db.create_session()

list = [
    "7229a0486d274d89b262a1cdf653f818",
    "cc77690aadea4d4c9b2a991bd5a052c3",
    "bba598327c494210bca98fb8b75ee668",
    "a12a7bcc113a410cac6c6717e3c16f08",
    "97e6e8aa69374cdcbe22e19f1f4b9fa5",
]
for i in list:
    coupon_template_info = session.query(MarketingCouponTemplate).filter_by(
        coupon_template_id=i
    ).first()
    print("*" * 60)
    print(session)
    print(
        coupon_template_info.coupon_template_name,
        coupon_template_info.create_time,
        coupon_template_info.coupon_template_id)
db.close_session(session)
"""
a = {
    "code": "200",
    "data": [
        {
            "subjectName": "租金",
            "subjectNumber": "1000000001",
            "coupon_list": ["1603261889258EA45coupon",
                            "16032618806113742coupon",
                            "1603261858437F6S7coupon",
                            "1603261825946DIV6coupon"]
        },
        {
            "subjectName": "押金",
            "subjectNumber": "1000000003",
            "coupon_list": ["1603261981891OLY7coupon"]
        },
        {
            "subjectName": "服务费",
            "subjectNumber": "5",
            "coupon_list": ["16032619753318628coupon",
                            "1603261963763R5K1coupon",
                            "1603261896999S488coupon",
                            "16032619300654XOAcoupon"]
        }
    ],
    "msg": "成功",
}

b = {
    "data": [
        {
            "subjectName": "租金",
            "subjectNumber": "1000000001",
            "coupon_list": ["1603261889258EA45coupon",
                            "16032618806113742coupon",
                            "1603261858437F6S7coupon",
                            "1603261825946DIV6coupon"]
        },
        {
            "subjectNumber": "1000000003",
            "coupon_list": ["1603261981891OLY7coupon"],
            "subjectName": "押金",
        },
        {
            "subjectName": "服务费",
            "subjectNumber": "5",
            "coupon_list": ["16032619753318628coupon",
                            "1603261896999S488coupon",
                            "1603261963763R5K1coupon",
                            "16032619300654XOAcoupon"]
        }
    ],
}

import operator

a_d = a["data"]
b_d = b["data"]


def abc(l):
    l['coupon_list'] = sorted(l.get("coupon_list"))
    return l


# print(list(map(abc, a_d)))
# print(list(map(abc, b_d)))
# print(operator.eq(list(map(abc, a_d)), list(map(abc, b_d))))
# for ad in a_d:
#     for bd in b_d:
#         if ad["subjectNumber"] == bd["subjectNumber"]:
#             try:
#                 assert ad["coupon_list"] == bd["coupon_list"]
#             except AssertionError:
#                 print("排序前")
#                 print(ad["coupon_list"])
#                 print(bd["coupon_list"])
#             ad["coupon_list"].sort()
#             bd["coupon_list"].sort()
#             try:
#                 assert ad["coupon_list"] == bd["coupon_list"]
#             except AssertionError:
#                 print("排序后")
#                 print(ad["coupon_list"])
#                 print(bd["coupon_list"])

